package kgame5.kengine.gameunit.impl {
import kgame5.kengine.events.FSMEvent;
import kgame5.kengine.events.SendCommandEvent;
import kgame5.kengine.gameunit.GUConstructorParam;
import kgame5.kengine.gameunit.GameUnit;
import kgame5.kengine.gameunit.parts.kfsm.FSM;

import flash.utils.Dictionary;

/**
 * @author kk
 * 游戏单位，有思维，具有fsm,控制一个并行状态机
 */
public class GUActor extends GameUnit{
	
	//保持各个fsm用来遍历用,并行状态机
	protected var dict_fsm:Dictionary;//dict_fsm[fsmID]=FSM
	
	public function GUActor(param:GUConstructorParam){
		super(param);
		
		dict_fsm=new Dictionary();
		
		//添加fsm
		if(param.arr_fsm!=null){
			for each(var fsm:FSM in param.arr_fsm){
				this.addFSM(fsm);
			}
		}
		
	}
	
	//#这里是更新各个fsm
	override public function update():void{
		
		super.update();
		
		//更新fsm
		for each(var fsm:FSM in dict_fsm){
			fsm.update();
		}
	}
	
	//==================操作FSMS=================
	//子类如果需要fsm通知guActor,可以覆写此函数
	private function addFSM(fsm:FSM):void{
		dict_fsm[fsm.getID()]=fsm;
		fsm.addEventListener(FSMEvent.TYPE, onFSMEvent);
		fsm.addEventListener(SendCommandEvent.TYPE, onSendCommandEvent);
		
		//暂存一下，方便以后传递到State中去
		fsm.setVO(this.vo);
		fsm.setHardVO(this.hard);
	}

	//从没用到过
//	public function removeFSM(fsmID:int):void{
//		delete dict_fsm[fsmID];
//	}
	
	public function findFSM(fsmID:int):FSM{
		return dict_fsm[fsmID];
	}
	
	//被子类覆写，有空定义一个好的FSMEvent
	protected function onFSMEvent(e:FSMEvent):void{
		/*var dd:XXX=e.getBody();
		 * switch(e.getName()){
		 * case xxx:
		 * this.executeGameCommand();
		 * break;
		 * }
		 */
	}
	
	
	
}//end of class
}
